package com.itheima.test04;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LogAspect {
    //execution、within
    @Pointcut("execution(* com.itheima.test04.UserService.*(..) )")
    public void pointCut() {}

    // 设置的访问权限
    @Around("pointCut()")
    public void log(ProceedingJoinPoint proceedingJoinPoint) {
        try {

        // 记录方法用时时间
        long begin = System.currentTimeMillis();

        proceedingJoinPoint.proceed();

        long end = System.currentTimeMillis();

        long diff = end - begin;
        System.out.println(diff + "ms");
        } catch (Throwable e) {
            System.out.println("有问题");
            throw new RuntimeException(e);
        }
    }
}
